package io.renren.modules.wap.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.commons.dynamic.datasource.annotation.DataSource;
import io.renren.modules.wap.dao.ExternalOrdersDao;
import io.renren.modules.wap.dto.ExternalOrdersDTO;
import io.renren.modules.wap.entity.ExternalOrdersEntity;
import io.renren.modules.wap.service.ExternalOrdersService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 对接三方订单
 *
 * @author Liang Pei 
 * @since 1.0.0 2025-01-02
 */
@Service
@DataSource("wap")
public class ExternalOrdersServiceImpl extends CrudServiceImpl<ExternalOrdersDao, ExternalOrdersEntity, ExternalOrdersDTO> implements ExternalOrdersService {

    @Override
    public QueryWrapper<ExternalOrdersEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<ExternalOrdersEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public List<ExternalOrdersEntity> getByPhoneAndAppId(String phone, String appId) {
        return baseDao.selectList(new QueryWrapper<ExternalOrdersEntity>()
                .eq("phone", phone)
                .eq("app_id", appId));
    }

    /**
     * 根据时间查询订单
     *
     * @return
     */
    @Override
    public List<ExternalOrdersEntity> getByDate(String startDate, String endDate) {
        return baseDao.selectList(new QueryWrapper<ExternalOrdersEntity>()
                .ge("create_time", startDate + " 00:00:00")
                .le("create_time", endDate + " 23:59:59"));
    }

    @Override
    public ExternalOrdersEntity getByOrderNo(String orderNo) {
        return baseDao.selectOne(new QueryWrapper<ExternalOrdersEntity>()
                .eq("order_no", orderNo));
    }


}